package com.medical_houduan.config;


import com.medical_houduan.filter.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration//声明配置类，注入ioc容器
public class WebConfig implements WebMvcConfigurer {

    @Autowired//自动注入拦截器
    private LoginInterceptor loginInterceptor;

    //注册拦截器
    @Override
    public void addInterceptors(InterceptorRegistry registry) {//InterceptorRegistry registry是一个拦截器注册器
        //注册拦截器
        registry.addInterceptor(loginInterceptor).excludePathPatterns("/user/login");//excludePathPatterns方法是排除在外，不拦截的路径




    }

    /*@Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") // 允许所有接口跨域
                .allowedOrigins("http://localhost:8081") // 允许前端域名
                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
                .allowedHeaders("*") // 允许所有请求头
                .allowCredentials(true) // 允许携带 Cookie
                .maxAge(3600); // 预检请求有效期（秒）
    }
*/





}
